// importM
import 'package:flutter/material.dart';

// ignore: unused_import
import './MyIcon.dart';

import './res/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(primarySwatch: Colors.blue),
      home: ListFul(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(child: Text("Hello Flutter"));
  }
}

// 动态加减
class HomePageFul extends StatefulWidget {
  const HomePageFul({super.key});

  @override
  State<HomePageFul> createState() => _HomePageFulState();
}

class _HomePageFulState extends State<HomePageFul> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Flutter App")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("$count", style: TextStyle(fontSize: 80)),
            SizedBox(height: 50),
            Row(
              // 主轴居中
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                IconButton(
                  onPressed: () {
                    setState(() {
                      count--;
                    });
                  },
                  icon: Icon(Icons.remove_circle),
                ),
                IconButton(
                  onPressed: () {
                    setState(() {
                      count++;
                    });
                  },
                  icon: Icon(Icons.add_circle),
                ),
              ],
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            count++;
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

// 动态列表
class ListFul extends StatefulWidget {
  const ListFul({super.key});

  @override
  State<ListFul> createState() => _ListFulState();
}

class _ListFulState extends State<ListFul> {
  final List<String> _list = <String>[];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("动态列表")),
      body: ListView(
        children: _list.map((value) {
          return ListTile(title: Text(value));
        }).toList(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _list.add("第${_list.length+1}条数据");
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}
